package com.orangelife.mobile.goodsOrder.biz;

import android.os.Handler;

import com.curry.android.http.HttpUtil;
import com.curry.android.util.StringUtil;
import com.orangelife.mobile.common.biz.JSONRequest;
import com.orangelife.mobile.constants.Constant;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by YangWei
 * on 2016/1/15.
 */
public class OrderHttp {

    /**
     * 设置已阅读
     */
    public static void setReadFlag(String orderID,Handler handler){
        String url = Constant.URL_MYGOODS_ORDER_READ;
        Map<String, Object> map = new HashMap<>();
        map.put("orderID", orderID);
        Map<String, Object> rootMap = new HashMap<>();
        rootMap.put("map", map);
        rootMap.put("url", url);
        rootMap.put("wat", OrderBiz.READ_FLAG);
        JSONRequest.getInstance().sendRequest(JSONRequest.PUT, rootMap, handler, HttpUtil.ACTION_JSON);
    }
    /**
     * 退回商品
     * @param map
     * @param handler
     */
    public static void postBackGood(Map<String,Object> map,Handler handler){
        String url = Constant.URL_MYGOODS_RETURN_PRODUCTS;
        Map<String, Object> rootMap = new HashMap<>();
        rootMap.put("map", map);
        rootMap.put("url", url);
        rootMap.put("wat", 1);
        JSONRequest.getInstance().sendRequest(JSONRequest.PUT, rootMap, handler, HttpUtil.ACTION_JSON);
    }
    /**
     * 确认收货
     * @param handler
     */
    public static void postConfirmRequest(String orderId,Handler handler){
        Map<String, Object> map = new HashMap<>();
        map.put("orderID", orderId);
        String url = Constant.URL_MYGOODS_ORDER_POST_CONFIRM;
        Map<String, Object> rootMap = new HashMap<>();
        rootMap.put("map", map);
        rootMap.put("url", url);
        rootMap.put("wat", OrderBiz.CONFIRM_GOOD);
        JSONRequest.getInstance().sendRequest(JSONRequest.PUT, rootMap, handler, HttpUtil.ACTION_JSON);
    }
    /**
     * 提交申请请求
     * @param map
     * @param handler
     */
    public static void postCancelRequest(Map<String,Object> map,Handler handler){
        String url = Constant.URL_MYGOODS_ORDER_POST_CANCEL;
        Map<String, Object> rootMap = new HashMap<>();
        rootMap.put("map", map);
        rootMap.put("url", url);
        rootMap.put("wat", 1);
        JSONRequest.getInstance().sendRequest(JSONRequest.POST, rootMap, handler, HttpUtil.ACTION_JSON);
    }


    /**
     * 获取原因列表
     * @param handler
     */
    public static void getCancelReason(Handler handler) {
        JSONRequest.getInstance()
                .sendRequest(JSONRequest.GET, Constant.URL_MYGOODS_ORDER_CANCEL_REASON
                        , new HashMap<String,Object>(), handler, 2, HttpUtil.ACTION_URI);
    }
    /**
     * 获取订单详情
     * @param orderId
     * @param handler
     */
    public static void getOrderDetail(String orderId,Handler handler){
        String url = Constant.URL_ORDER_DETAIL;
        Map<String, Object> map = new HashMap<>();
        map.put("{orderID}", orderId);
        Map<String, Object> rootMap = new HashMap<>();
        rootMap.put("map", map);
        rootMap.put("url", url);
        rootMap.put("wat", OrderBiz.DETAIL_LIST);
        JSONRequest.getInstance().sendRequest(JSONRequest.GET, rootMap, handler, HttpUtil.ACTION_URI);
    }


    /**
     * 获取未读数量
     * @param handler
     */
    public static void getOrderMsgNum(Handler handler) {
        JSONRequest.getInstance()
                .sendRequest(JSONRequest.GET, Constant.URL_MYGOODS_ORDER_NUM
                        , new HashMap<String,Object>(), handler, 2, HttpUtil.ACTION_URI);
    }
    /**
     * 获取我的商品订单列表
     */
    public static void getMyGoodsOrderList(String search, int status, int pageSize, int pageNo, Handler handler) {
        Map<String, Object> map = new HashMap<>();
        if (!StringUtil.isBlank(search)) {
            map.put("search", search);
        }
        map.put("status", status + "");
        map.put("pageIndex", pageNo);
        map.put("pageSize", pageSize);
        JSONRequest.getInstance().sendRequest(JSONRequest.GET, Constant.URL_MYGOODS_ORDER_LIST_NEW, map, handler, 1, HttpUtil.ACTION_URI);
    }
}
